package org.example.graphql;

//import cn.hutool.core.io.FileUtil;
//import graphql.GraphQL;
//import graphql.schema.GraphQLSchema;
//import graphql.schema.StaticDataFetcher;
//import graphql.schema.idl.*;
import lombok.RequiredArgsConstructor;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Bean;
//import org.springframework.stereotype.Component;
//
//import javax.annotation.PostConstruct;
//import java.net.URL;

//@Component
@RequiredArgsConstructor
public class GraphQLProvider {

//    final GraphQLDataFetchers graphQLDataFetchers;
//
//    private GraphQL graphQL;
//
//    @PostConstruct
//    public void init() {
//        String sdl = FileUtil.readUtf8String("schema.graphqls");
//        GraphQLSchema graphQLSchema = buildSchema(sdl);
//        this.graphQL = GraphQL.newGraphQL(graphQLSchema).build();
//    }
//
//    @Bean
//    public GraphQL graphQL() {
//        return this.graphQL;
//    }
//
//    private GraphQLSchema buildSchema(String sdl) {
//        TypeDefinitionRegistry typeDefinitionRegistry = new SchemaParser().parse(sdl);
//        RuntimeWiring runtimeWiring = buildWiring();
//        SchemaGenerator schemaGenerator = new SchemaGenerator();
//        return schemaGenerator.makeExecutableSchema(typeDefinitionRegistry, runtimeWiring);
//    }
//
//    private RuntimeWiring buildWiring() {
//        return RuntimeWiring.newRuntimeWiring()
//                .type("Mutation", builder -> builder.dataFetcher("hello", new StaticDataFetcher("Mutation hello world")))
//                .type("Query", builder -> builder.dataFetcher("hello", new StaticDataFetcher("Query hello world")))
//                .type(TypeRuntimeWiring.newTypeWiring("Query").dataFetcher("bookById", graphQLDataFetchers.getBookByIdDataFetcher()))
//                .type(TypeRuntimeWiring.newTypeWiring("Query").dataFetcher("books", graphQLDataFetchers.getAllBooks()))
//                .type(TypeRuntimeWiring.newTypeWiring("Book").dataFetcher("author", graphQLDataFetchers.getAuthorDataFetcher()))
//                .build();
//    }

}
